package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.auto.CombinedForm;
import com.fc.v2.model.auto.Scaletab;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.Detection;
import com.fc.v2.service.DetectionService;
import com.fc.v2.service.ScaletabService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;


/**
 * 检测信息Controller
 * @ClassName: DetectionController
 * @author cjh
 * @date 2025-01-29 19:14:18
 */
@Api(value = "检测信息")
@Controller
@RequestMapping("/DetectionController")
public class DetectionController extends BaseController{
	
	private String prefix = "gen/detection";
	private String shprefix = "gen/shenhe";
	@Autowired
	private DetectionService detectionService;

	@Autowired
	private ScaletabService scaletabService;
	/**
	 * 检测信息页面展示
	 * @param model
	 * @return String
	 * @author cjh
	 */
	@ApiOperation(value = "分页跳转", notes = "待检测列表")
	@GetMapping("/view")
	@SaCheckPermission("gen:detection:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	/**
	 * 检测信息审核页面展示
	 * @param model
	 * @return String
	 * @author cjh
	 */
	@ApiOperation(value = "审核", notes = "审核")
	@GetMapping("/viewsh")
	@SaCheckPermission("gen:detection:view")
	public String viewsh(ModelMap model)
	{
		return shprefix + "/list";
	}
	/**
	 * 打印页面展示
	 * @param model
	 * @return String
	 * @author cjh
	 */
	@ApiOperation(value = "打印", notes = "打印")
	@GetMapping("/viewprint")
	@SaCheckPermission("gen:detection:view")
	public String viewprint(ModelMap model)
	{
		return shprefix + "/printlist";
	}
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "检测信息", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@SaCheckPermission("gen:detection:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,Detection detection){
		PageInfo<Detection> page=detectionService.list(tablepar,detection) ; 
		return pageTable(page.getList(),page.getTotal());
	}
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "检测信息", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/listnotIn")
	@SaCheckPermission("gen:detection:list")
	@ResponseBody
	public ResultTable listnotIn(Tablepar tablepar,Detection detection){
		PageInfo<Detection> page=detectionService.listnotIn(tablepar,detection) ;
		return pageTable(page.getList(),page.getTotal());
	}
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "检测信息", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/listShenhe")
	@SaCheckPermission("gen:detection:list")
	@ResponseBody
	public ResultTable listShenhe(Tablepar tablepar,Detection detection){
		PageInfo<Detection> page=detectionService.listShenhe(tablepar,detection) ;
		return pageTable(page.getList(),page.getTotal());
	}

	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "检测信息", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/printlist")
	@SaCheckPermission("gen:detection:list")
	@ResponseBody
	public ResultTable printlist(Tablepar tablepar,Detection detection){
		PageInfo<Detection> page=detectionService.listPrint(tablepar,detection) ;
		return pageTable(page.getList(),page.getTotal());
	}
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "检测信息", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/listPrint")
	@SaCheckPermission("gen:detection:list")
	@ResponseBody
	public ResultTable listPrint(Tablepar tablepar,Detection detection){
		PageInfo<Detection> page=detectionService.listPrint(tablepar,detection) ;
		return pageTable(page.getList(),page.getTotal());
	}
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "检测信息新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@SaCheckPermission("gen:detection:add")
	@ResponseBody
	public AjaxResult add(Detection detection){
		int b=detectionService.insertSelective(detection);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 检测信息删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "检测信息删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@SaCheckPermission("gen:detection:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=detectionService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        map.put("Detection", detectionService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }

	/**
	 * 审核跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "审核跳转", notes = "审核跳转")
	@GetMapping("/editsh/{id}")
	public String editsh(@PathVariable("id") String id, ModelMap map)
	{

		Detection detection= detectionService.selectByPrimaryKey(id);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

		// 将 Date 对象格式化为字符串
		detection.setQdtime(sdf.format(detection.getCreatetime()));
		Scaletab  scaletab =scaletabService.listtop1(id);

		CombinedForm combinedForm =new CombinedForm(detection,scaletab);
		map.put("combinedForm",combinedForm);

		String selectedValue=detection.getMpe1();
		String path =getEditPath(selectedValue,shprefix);
		return path;

	}

	public static String getEditPath(String selectedValue, String prefix) {

		if (selectedValue == null) {
			throw new IllegalArgumentException("selectedValue不能为null");
		}

		switch (selectedValue) {
			case "E2":
			case "F1":
				return prefix + "/editabba";
			case "F2":
			case "M1":
				return prefix + "/editaba";
			case "E6":
				return prefix + "/editabba6";
			case "A6":
				return prefix + "/editaaaa6";
			case "E10":
				return prefix + "/editabba10";
			default:
				throw new IllegalArgumentException("未知的selectedValue: " + selectedValue);
		}
	}
	/**
	 * 审核跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "审核跳转", notes = "审核跳转")
	@GetMapping("/print/{id}")
	public String print(@PathVariable("id") String id, ModelMap map)
	{

		Detection detection= detectionService.selectByPrimaryKey(id);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

		// 将 Date 对象格式化为字符串
		detection.setQdtime(sdf.format(detection.getCreatetime()));
		Scaletab  scaletab =scaletabService.listtop1(id);

		CombinedForm combinedForm =new CombinedForm(detection,scaletab);
		map.put("combinedForm",combinedForm);

		String selectedValue=detection.getMpe1();

		String path =printPath(selectedValue,shprefix);
		// 根据不同的值决定请求的 URL

		return path;

	}


	public static String printPath(String selectedValue, String prefix) {
		if (selectedValue == null) {
			throw new IllegalArgumentException("selectedValue不能为null");
		}

		switch (selectedValue) {
			case "E2":
			case "F1":
				return prefix + "/printabba";
			case "F2":
			case "M1":
				return prefix + "/printaba";
			case "E6":
				return prefix + "/printabba6";
			case "A6":
				return prefix + "/printaaaa6";
			case "E10":
				return prefix + "/printabba10";
			default:
				throw new IllegalArgumentException("未知的selectedValue: " + selectedValue);
		}
	}

	/**
     * 修改保存
     */
    //@Log(title = "检测信息修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @SaCheckPermission("gen:detection:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Detection detection)
    {
        return toAjax(detectionService.updateByPrimaryKeySelective(detection));
    }
    
    
    /**
	 * 修改状态
	 * @param record
	 * @return
	 */
    @PutMapping("/updateVisible")
	@ResponseBody
    public AjaxResult updateVisible(@RequestBody Detection detection){
		int i=detectionService.updateVisible(detection);
		return toAjax(i);
	}

    
    

	
}
